<?php 

$page           = (!empty($_GET['page-id']) && is_numeric($_GET['page-id'])) ? $_GET['page-id'] : 1;
$filter_keyword = (!empty($_GET['query'])) ? Wo_Secure($_GET['query']) : '';
$filter_type    = '';
$db->pageLimit  = 20;


if (!empty($filter_keyword)) {
  $sql   = "(
    `username`     LIKE '%$filter_keyword%' OR 
    `email`        LIKE '%$filter_keyword%' OR 
    `first_name`   LIKE '%$filter_keyword%' OR 
    `ip_address`   LIKE '%$filter_keyword%' OR 
    `phone_number` LIKE '%$filter_keyword%' OR 
    `last_name`    LIKE '%$filter_keyword%'
  )";
  
  $pro_users = $db->where($sql)->where('is_pro','1')->orderBy('user_id', 'DESC')->objectbuilder()->paginate(T_USERS, $page);
} 

else {
  $pro_users = $db->where('is_pro','1')->objectbuilder()->orderBy('user_id', 'DESC')->paginate(T_USERS, $page);
}

if (($page > $db->totalPages) && !empty($_GET['page-id'])) {
  header("Location: " . Wo_LoadAdminLinkSettings('pro-memebers'));
  exit();
}

?>
<div class="container-fluid">
    <div class="block-header">
        <h2>专业版系统 > 管理专业版成员</h2>
    </div>
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="header">
                    <h2>专业版成员</h2>
                    <button onclick="Wo_CancelPro();" type="button" class="button-cancel btn btn-danger waves-effect waves-light m-t-10"> 取消过期订阅</button>
                </div>
                <div class="body">
                  <div class="row">
                      <div class="col-md-4" style="margin-bottom:0;">
                        <form method="get" action="<?php echo Wo_LoadAdminLinkSettings('pro-memebers'); ?>">
                          <div class="row">
                            <div class="col-md-11">
                              <div class="form-group form-float">
                                  <div class="form-line">
                                      <input type="text" name="query" id="query" class="form-control" value="<?php echo($filter_keyword); ?>">
                                      <label class="form-label search-form">
                                        搜索用户名，电子邮件，名字，姓氏
                                      </label>
                                  </div>
                              </div>
                            </div>
                            <div class="col-md-1">
                               <button class="btn btn-info">搜索</button>
                            </div>
                          </div>
                          <div class="clearfix"></div>
                        </form>
                      </div>
                  </div>
                  <div class="table-responsive1">
                        <table class="table table-bordered table-striped table-hover">
                          <thead>
                            <tr>
                              <th>ID</th>
    				                  <th>用户名</th>
    				                  <th>专业版类型</th>
    				                  <th>已订阅</th>
    				                  <th>状态</th>
    				                  <th>操作</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php 
    				                  foreach ($pro_users as $userlist) {
                                $wo['userlist'] = Wo_UserData($userlist->user_id);
    				                    echo Wo_LoadAdminPage('pro-memebers/list');
    				                  }
    				                ?>
                          </tbody>
                        </table>
                  </div>
                  <div class="wo-admincp-feturepager">
                    <div class="pull-left">
                        <span>
                          <?php echo "显示 $page 一共 " . $db->totalPages; ?>
                        </span>
                    </div>
                    <div class="pull-right">
                      <nav>
                          <ul class="pagination">
                              <li>
                                <a href="<?php echo Wo_LoadAdminLinkSettings('pro-memebers?page-id=1'); ?>" class="waves-effect" title='第一页'>
                                    <i class="material-icons">first_page</i>
                                </a>
                              </li>
                              <?php if ($page > 1) {  ?>
                                <li>
                                    <a href="<?php echo Wo_LoadAdminLinkSettings('pro-memebers?page-id=' . ($page - 1)); ?>" class="waves-effect" title='上一页'>
                                        <i class="material-icons">chevron_left</i>
                                    </a>
                                </li>
                              <?php  } ?>

                              <?php 
                                $nums       = 0;
                                $nums_pages = ($page > 4) ? ($page - 4) : $page;

                                for ($i=$nums_pages; $i <= $db->totalPages; $i++) { 
                                  if ($nums < 20) {
                              ?>
                                <li class="<?php echo ($page == $i) ? 'active' : ''; ?>">
                                  <a href="<?php echo Wo_LoadAdminLinkSettings('pro-memebers?page-id=' . ($i)); ?>" class="waves-effect">
                                    <?php echo $i ?>   
                                  </a>
                                </li>

                              <?php } $nums++; }?>

                              <?php if ($db->totalPages > $page) { ?>
                                <li>
                                    <a href="<?php echo Wo_LoadAdminLinkSettings('pro-memebers?page-id=' . ($page + 1)); ?>" class="waves-effect" title="下一页">
                                        <i class="material-icons">chevron_right</i>
                                    </a>
                                </li>
                              <?php } ?>
                              <li>
                                <a href="<?php echo Wo_LoadAdminLinkSettings('pro-memebers?page-id=' . ($db->totalPages)); ?>" class="waves-effect" title='最后页'>
                                    <i class="material-icons">last_page</i>
                                </a>
                              </li>
                          </ul>
                      </nav>
                    </div>
                  </div>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    </div>
<script>

function Wo_CancelPro() {
   $('.button-cancel').text('Please wait..');
   $.get(Wo_Ajax_Requests_File(), {f: 'admin_setting', s:'cancel_pro'}, function(data) {
      if (data.status == 200) {
      	 $('.button-cancel').text('已过期的订阅已被清除');
      }
   });
}

</script>